package com.flymobi.service;

import java.util.List;

import com.flymobi.fw.modules.CommonService;
import com.flymobi.fw.util.StringUtil;
import com.flymobi.po.Users;
import com.flymobi.util.QL;

public class UsersService extends CommonService {
/*	public List<UsersVo> list(String startMonth, String startDay,String endMonth,String endDay,Long days,Long count) {
		return dao.executeQueryBySQL(UsersVo.class,QL.SQL.SQLSERVER.EXP,new Object[]{startMonth,startDay,endMonth,endDay,days,count});	
	}*/
	
	public List<Users> list(String key, int startRows, int rows) {
		if (StringUtil.isEmpty(key)) {
			key = "";
		}
		return dao.find(Users.class, QL.HQL.Users.LIST_BY_KEY,
				new Object[] { "%" + key + "%", "%" + key + "%" }, startRows, rows);
	}

	public Long getCount(String key) {
		if (StringUtil.isEmpty(key)) {
			key = "";
		}
		return dao.getCount(QL.HQL.Users.GET_COUNT_KEY, new Object[] { "%"
				+ key + "%", "%" + key + "%" });
	}
	
	public Users find(String namEmailMobile){
		return dao.findSingle(Users.class, QL.HQL.Users.FIND_BY_NAMEEMAILMOBILE,
				new Object[] { namEmailMobile, namEmailMobile,namEmailMobile});
	}
	
	public Users findName(String name){
		return dao.findSingle(Users.class, QL.HQL.Users.FIND_BY_Name,
			  new Object[] {name});
	}
	
	public Users login(String name,String pwd){
		Users u=find(name);
		if(u==null){
			return null;
		}
		if(u.getPwd().equals(pwd)){
			dao.save(u);
			return u;
		}else{
			return null;
		}
	}

	public void save(Users users) {
		dao.save(users);
	}

	public Users load(String id) {
		return dao.load(Users.class, new Long(id));
	}

	public Users get(String id) {
		return dao.get(Users.class, new Long(id));
	}

	public void delete(String id) {
		dao.delete(this.get(id));
	}
}
